# $Id$

class ProjectReportTeam < ActiveRecord::Base
  unloadable

  belongs_to :project
  belongs_to :form, :class_name => "ProjectReportForm", :foreign_key => "project_report_form_id"
  has_and_belongs_to_many :members, :class_name=>"User"

  def total_spent_hours
    return @spent_hours if @spent_hours
    member_id_list = []
    members.each {|member| member_id_list << "'#{member.id}'"}
    @spent_hours = TimeEntry.sum(:hours, :conditions => ["#{TimeEntry.table_name}.project_id = ? and #{TimeEntry.table_name}.user_id IN (#{member_id_list.join(",")})", self.project ])
  end

end
